﻿using System;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
using Cashier_Utils;

namespace Cashier_DAO.db
{
    public class MySQLConnectionInstance
    {
        private static String dbPath = String.Empty;

        static MySQLConnectionInstance()
        {
            dbPath = String.Format("server={0};user id={1}; password={2}; database={3}; pooling=true",
                    DbConfig.Host, EncryptionUtil.DesDecode(DbConfig.Username), EncryptionUtil.DesDecode(DbConfig.Password), DbConfig.Dbname);
        }

        /// <summary>
        /// 返回MySqlConnection实例
        /// </summary>
        /// <returns></returns>
        public static MySqlConnection GetMySqlConnection()
        {
            MySqlConnection conn = null;
            try
            {
                conn = new MySqlConnection(dbPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return conn;
        }
    }
}
